<html>
<head><meta charset="utf-8"><title>Playground segfault · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html">Playground segfault</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="230231355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230231355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230231355">(Mar 14 2021 at 11:10)</a>:</h4>
<p>Hello everyone!<br>
Just tried this small code snippet <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f5501d69b691435bbdcf9c758de6111b">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f5501d69b691435bbdcf9c758de6111b</a><br>
and it made the playground segfault.<br>
Where / how such problems should be reported?</p>



<a name="230231494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230231494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230231494">(Mar 14 2021 at 11:13)</a>:</h4>
<p>Oh but its rustc generating an invalid program here.<br>
I tried locally with 1.50.0 and the generated binary segfault when executed :/</p>



<a name="230231596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230231596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230231596">(Mar 14 2021 at 11:15)</a>:</h4>
<p>rust-lang/rust issue tracker in that case</p>



<a name="230231621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230231621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230231621">(Mar 14 2021 at 11:15)</a>:</h4>
<p>Yeah sorry, I originally thought it was a playground specific issue</p>



<a name="230236812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230236812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230236812">(Mar 14 2021 at 12:57)</a>:</h4>
<p>I am pretty sure that this is caused by the <code>#[no_mangle] fn free()</code> overwriting the <code>free</code> function exported by the memory allocator and then interpreting the argument as <code>Option&lt;Box&lt;usize&gt;&gt;</code> which is dropped, thus causing <code>Box</code> to call <code>free</code> again recursively.</p>



<a name="230236897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230236897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230236897">(Mar 14 2021 at 12:59)</a>:</h4>
<p>yeah, no_mangle is sadly a silent unsafe...</p>



<a name="230265569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230265569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230265569">(Mar 14 2021 at 20:25)</a>:</h4>
<p>Yeah I figured that out when I looked at the gdb backtrace :D</p>



<a name="230280291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230280291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230280291">(Mar 15 2021 at 00:05)</a>:</h4>
<p>perhaps we should lint against "safe" <code>#[no_mangle] fn</code>? (allowing <code>unsafe fn</code>)</p>



<a name="230280483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230280483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230280483">(Mar 15 2021 at 00:08)</a>:</h4>
<p>I think it's a pending PR</p>



<a name="230280499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230280499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230280499">(Mar 15 2021 at 00:08)</a>:</h4>
<p>hmm, although <code>#[no_mangle] static</code> exists too -- extra safety points for masking a function that way...</p>



<a name="230281167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230281167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230281167">(Mar 15 2021 at 00:21)</a>:</h4>
<p>Could llvm detect function symbol clashes?</p>



<a name="230282711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230282711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230282711">(Mar 15 2021 at 00:52)</a>:</h4>
<p>it's more the linker's domain</p>



<a name="230282841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230282841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230282841">(Mar 15 2021 at 00:55)</a>:</h4>
<p>LLVM probably would notice if you declared and defined conflicting functions in the same compilation unit, but in this case I expect the use of the normal <code>free</code> is out of sight in std</p>



<a name="230282916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230282916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230282916">(Mar 15 2021 at 00:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Playground.20segfault/near/230280483">said</a>:</p>
<blockquote>
<p>I think it's a pending PR</p>
</blockquote>
<p>do you mean <a href="https://github.com/rust-lang/rust/pull/72209">https://github.com/rust-lang/rust/pull/72209</a> ? that adds the lint to <code>unsafe_code</code>, but it's not on by default</p>



<a name="230283215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230283215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230283215">(Mar 15 2021 at 01:03)</a>:</h4>
<p>We attempt to detect conflicting symbols to the point where its feasible to do so in rustc for a long long time now.</p>



<a name="230283290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230283290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230283290">(Mar 15 2021 at 01:04)</a>:</h4>
<p><code>unsafe_code</code> is sounding like a lint I want to enable pretty much everywhere ^^</p>



<a name="230323456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230323456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230323456">(Mar 15 2021 at 10:39)</a>:</h4>
<p>cc <a href="https://github.com/rust-lang/rust/issues/83111">#83111</a></p>



<a name="230323629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230323629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230323629">(Mar 15 2021 at 10:41)</a>:</h4>
<p>It's interesting that Miri can't catch anything in that code.</p>



<a name="230323880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230323880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230323880">(Mar 15 2021 at 10:43)</a>:</h4>
<p>Miri doesn't run libc. It merely emulates it. It also intercepts <code>#[global_allocator]</code>. Combined this means that <code>free</code> is simply never called by miri.</p>



<a name="230326223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230326223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230326223">(Mar 15 2021 at 11:02)</a>:</h4>
<p>Miri can't catch anything in this code either:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[no_mangle]</span><span class="w"></span>
<span class="k">extern</span><span class="w"> </span><span class="s">"C"</span><span class="w"> </span><span class="k">fn</span> <span class="nf">write</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="fm">println!</span><span class="p">(</span><span class="s">"Hello World!"</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Even though, IIUC, Miri does emulate <code>write</code>: <a href="https://github.com/rust-lang/miri/blob/0788188c7b586289edb878f1f5b4e23700671978/src/shims/posix/fs.rs#L640">https://github.com/rust-lang/miri/blob/0788188c7b586289edb878f1f5b4e23700671978/src/shims/posix/fs.rs#L640</a></p>



<a name="230326515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230326515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230326515">(Mar 15 2021 at 11:05)</a>:</h4>
<p>Exactly, it emulates <code>write</code>, meaning that your <code>write</code> impl is never used.</p>



<a name="230327019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230327019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230327019">(Mar 15 2021 at 11:09)</a>:</h4>
<p>Sadly, in practice, my <code>write</code> will take priority, otherwise it won't segfault. <span aria-label="frown" class="emoji emoji-1f641" role="img" title="frown">:frown:</span></p>



<a name="230327273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230327273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230327273">(Mar 15 2021 at 11:10)</a>:</h4>
<p>The dynamic linker prefers symbols from the executable over symbols from dynamic libraries as the executable is loaded first.</p>



<a name="230327336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Playground%20segfault/near/230327336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Playground.20segfault.html#230327336">(Mar 15 2021 at 11:11)</a>:</h4>
<p><code>LD_PRELOAD</code> is loaded even before the executable. This is what allows interposition using <code>LD_PRELOAD</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>